﻿@using Rail.Net.Common.Resources
@model Rail.Net.Core.Model.Nonpersistent.ClientDataModel

<script type="text/javascript">

function ClientDataValidate() {
    alert($('#ClientDataForm').validate());
    alert($('#ClientDataForm').validate().form());
    return $('#ClientDataForm').validate().form();
}


function PaymentBegin() {
    if (ClientDataValidate()) {
        $('#payment-content').html("");
        $('#ticket-content').html("");
        $.blockUI({
            css:
        {
            width: '700px',
            height: '500px',
            top: ($(window).height() - 500) / 2 + 'px',
            left: ($(window).width() - 700) / 2 + 'px'
        },
            message: $('#loading')
        });
    }
}
function PaymentSuccess() {
    $.unblockUI();
    $('payment').append('<div style="clear:both"></div>');
    $('a[href="#payment"]').triggerHandler('click');
    $('a[href="#payment"]').triggerHandler('change');
    
//    $('#tabs').tabs('select', '#payment');
}

function PaymentFailure() {
    $.unblockUI();
    alert("Error occured!");
}

var cdTable1;
var cdTable2;

$(document).ready(function () {
    cdTable1 = $('#clientDataTable1').dataTable({
        "bJQueryUI": true,
        "bFilter": false,
        "bSort": false,
        "bPaginate": false,
        "bInfo": false,
        "bStateSave": true,
        "oLanguage": {
            "sProcessing": "@Global.DataTable_sProcessing",
            "sLengthMenu": "@Global.DataTable_sLengthMenu",
            "sZeroRecords": "@Global.DataTable_sZeroRecords",
            "sInfo": "@Global.DataTable_sInfo",
            "sInfoEmpty": "@Global.DataTable_sInfoEmpty",
            "sInfoFiltered": "@Global.DataTable_sInfoFiltered",
            "sInfoPostFix": "@Global.DataTable_sInfoPostFix",
            "sSearch": "@Global.DataTable_sSearch",
            "sUrl": "@Global.DataTable_sUrl",
            "oPaginate": {
                "sFirst": "@Global.DataTable_oPaginate_sFirst",
                "sPrevious": "@Global.DataTable_oPaginate_sPrevious",
                "sNext": "@Global.DataTable_oPaginate_sNext",
                "sLast": "@Global.DataTable_oPaginate_sLast"
            }
        }
    });

    cdTable2 = $('#clientDataTable2').dataTable({
        "bJQueryUI": true,
        "bFilter": false,
        "bSort": false,
        "bPaginate": false,
        "bInfo": false,
        "bStateSave": true,
        "oLanguage": {
            "sProcessing": "@Global.DataTable_sProcessing",
            "sLengthMenu": "@Global.DataTable_sLengthMenu",
            "sZeroRecords": "@Global.DataTable_sZeroRecords",
            "sInfo": "@Global.DataTable_sInfo",
            "sInfoEmpty": "@Global.DataTable_sInfoEmpty",
            "sInfoFiltered": "@Global.DataTable_sInfoFiltered",
            "sInfoPostFix": "@Global.DataTable_sInfoPostFix",
            "sSearch": "@Global.DataTable_sSearch",
            "sUrl": "@Global.DataTable_sUrl",
            "oPaginate": {
                "sFirst": "@Global.DataTable_oPaginate_sFirst",
                "sPrevious": "@Global.DataTable_oPaginate_sPrevious",
                "sNext": "@Global.DataTable_oPaginate_sNext",
                "sLast": "@Global.DataTable_oPaginate_sLast"
            }
        }
    });

    $('#client-data-back-btn').click(function (e) {
        e.preventDefault();
        //$('#tabs').tabs('select', 0);
        $('a[href="#offers"]').triggerHandler('click');
        $('a[href="#offers"]').triggerHandler('change');

        return false;
    });

    $('#offers-next-btn').click(function (event) {
        return true;
    });
    
    $('div .dataTables_wrapper div').each(function (i) {
        $(this).removeClass("ui-widget-header");
    });

    $('table tbody tr').each(function (i) {
        $(this).removeClass("ui-state-highlight");
    });
});

</script>

@{ Html.EnableClientValidation(); }
@using (Ajax.BeginForm("Payment", "Ticket", new {}, new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "payment-content", InsertionMode = System.Web.Mvc.Ajax.InsertionMode.Replace, OnBegin = "PaymentBegin", OnSuccess = "PaymentSuccess", OnFailure = "PaymentFailure" }, new { id = "ClientDataForm"}))
{
    <fieldset>
        <legend>@Global.Main_BreadCrumb_ClientData</legend>
        <h2>
            @Model.OutwardProduct.Connection.FirstStation.Name - @Model.OutwardProduct.Connection.LastStation.Name, @Model.OutwardProduct.Connection.DepartureTime.ToShortDateString()
        </h2>
        @Html.HiddenFor(m => m.OutwardProductId)

        <div class="efield">
            <div class="elabel">@Global.Main_ClientData_Price:</div>
            <div class="einput">@Model.OutwardProduct.Price.ToString("0.00") €</div>            
        </div>
        <div class="efield">
            <div class="elabel">@Global.Main_ClientData_Travelers:</div>
            <div class="einput">
                <ul>
                    @{
                        foreach (var travelerModel in Model.SearchModel.Travelers)
                        {   
                            <li>@(travelerModel.Age.SelectedItem.Name) @(travelerModel.Discount.SelectedItem.Name)</li>
                        }
                    }
                </ul>
            </div>            
        </div>
        <div class="efield">
            <div class="elabel">@Global.Main_ClientData_Connection:</div>
            <div class="einput">
                <table id="clientDataTable1" class="dataTable">
                    <thead>
                        <tr>
                            <th>
                                @Global.Main_ClientData_Train
                            </th>
                            <th>
                                @Global.Main_ClientData_FromStation
                            </th>
                            <th>
                                @Global.Main_ClientData_DepartureTime
                            </th>            
                            <th>
                                @Global.Main_ClientData_ToStation
                            </th>
                            <th>
                                @Global.Main_ClientData_ArrivalTime
                            </th>
                            <th>
                                @Global.Main_ClientData_Reservation
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        @{
                        foreach (var train in Model.OutwardProduct.Connection.Trains)
                        {   
                            <tr>
                                <td style="white-space: nowrap;">
                                    @train.Label @train.Number
                                </td>
                                <td>
                                    @train.Departure.Name
                                </td>
                                <td class="right">
                                    @train.Departure.DepartureTime.ToShortTimeString()
                                </td>
                                <td>
                                    @train.Arrival.Name
                                </td>
                                <td class="right">
                                    @train.Arrival.ArrivalTime.ToShortTimeString()
                                </td>
                                <td class="right">
                            
                                </td>
                            </tr>
                        }}
                    </tbody>
                </table>
            </div>            
        </div>
        
        <div style="clear:both;"></div>

        @if (Model.ReturnProduct != null)
        {
            <h2>
                @Model.ReturnProduct.Connection.FirstStation.Name - @Model.ReturnProduct.Connection.LastStation.Name, @Model.ReturnProduct.Connection.DepartureTime.ToShortDateString()
            </h2>
            
            @Html.HiddenFor(m => m.ReturnProductId)
            
            <div class="efield">
                <div class="elabel">@Global.Main_ClientData_Price:</div>
                <div class="einput">@Model.ReturnProduct.Price.ToString("0.00") €</div>            
            </div>
            <div class="efield">
                <div class="elabel">@Global.Main_ClientData_Travelers:</div>
                <div class="einput">
                    <ul>
                        @{
            foreach (var travelerModel in Model.SearchModel.Travelers)
            {
                                <li>@(travelerModel.Age.SelectedItem.Name) @(travelerModel.Discount.SelectedItem.Name)</li>
            }
                        }
                    </ul>
                </div>            
            </div>
            <div class="efield">
                <div class="elabel">@Global.Main_ClientData_Connection:</div>
                <div class="einput">
                    <table id="clientDataTable2" class="dataTable">
                        <thead>
                            <tr>
                                <th>
                                    @Global.Main_ClientData_Train
                                </th>
                                <th>
                                    @Global.Main_ClientData_FromStation
                                </th>
                                <th>
                                    @Global.Main_ClientData_DepartureTime
                                </th>            
                                <th>
                                    @Global.Main_ClientData_ToStation
                                </th>
                                <th>
                                    @Global.Main_ClientData_ArrivalTime
                                </th>
                                <th>
                                    @Global.Main_ClientData_Reservation
                                </th>
                            </tr>
                        </thead>
                        <tbody>
                            @{
            foreach (var train in Model.ReturnProduct.Connection.Trains)
            {   
                                <tr>
                                    <td style="white-space: nowrap;">
                                        @train.Label @train.Number
                                    </td>
                                    <td>
                                        @train.Departure.Name
                                    </td>
                                    <td class="right">
                                        @train.Departure.DepartureTime.ToShortTimeString()
                                    </td>
                                    <td>
                                        @train.Arrival.Name
                                    </td>
                                    <td class="right">
                                        @train.Arrival.ArrivalTime.ToShortTimeString()
                                    </td>
                                    <td class="right">
                                    </td>
                                </tr>
            }}
                        </tbody>
                    </table>
                </div>            
            </div>
        }
        <h2>
            @Global.Main_ClientData_TravelerData
        </h2>
        @Html.EditorFor(model => model.FirstName)
        @Html.EditorFor(model => model.LastName)
        @Html.EditorFor(model => model.Email)
        @Html.EditorFor(model => model.AcceptTerms)
    </fieldset>
    <div class="center">
        <input id="client-data-back-btn" type="submit" name="ClientDataBackBtn" value="@Global.Main_ClientData_Back" />
        <input id="client-data-next-btn" type="submit" name="ClientDataNextBtn" value="@Global.Main_ClientData_Next" />
    </div>
}